package com.tianqu.tms.www.user.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.user.actionform.UserInputActionForm;
import com.tianqu.tms.www.user.controller.UserUDDetailController;
import com.tianqu.tms.www.user.viewhelper.UserDetailViewHelper;

/**
 * 用户查看信息页
 * 
 * @author tianshifu
 *
 */

public class UserUDDetailAction extends TmsAction {
		
	private Logger logger = Logger.getLogger(UserUDDetailAction.class);
	
	private static final String ID = "id";
	
	private static final String VIEW = "view";

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		UserInputActionForm inputForm = (UserInputActionForm)form;
		
		String id = request.getParameter(ID);
		if(StringUtil.isNullOrBlank(id)){
			UserDetailViewHelper view = new UserDetailViewHelper();
			view = (UserDetailViewHelper)uc.getAttribute(VIEW);
			id = view.getId();
		}
		uc.setAttribute(ID, id);
		inputForm.setId(Long.parseLong(id));
		
		UserUDDetailController controller = new UserUDDetailController();
		controller.execute(uc);
		
		//将查看信息抛到前台 此处还需要传递参数判断按钮
		
		request.setAttribute(TmsConstants.VIEWHELP, uc.getAttribute(VIEW));
		
		// TODO Auto-generated method stub
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
